#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>

int abs(a, b)
{
	if (a > b)
		return a - b;
	else
		return b - a;
}
struct listNode* getIntersectionNode(struct listNode* headA, struct listNode* headB)
{
	if (headA== NULL || headB== NULL)
		return NULL;
	struct listNode* cur1 = headA;
	struct listNode* cur2 = headB;
	int lenA = 0;
	while (cur1 != NULL)
	{
		cur1 = cur1->next;
		lenA++;
	}
	int lenB = 0;
	while (cur2 != NULL)
	{
		cur2 = cur2->next;
		lenB++;
	}
	struct listNode* longlist = headA;
	struct listNode* shortlist = headB;
	if (lenA < lenB)
	{
		longlist = lenB;
		shortlist = lenA;
	}
	int gap = abs(lenA - lenB);
	while (gap--)
	{
		longlist = longlist->next;
	}
	while (longlist != shortlist)
	{
		longlist = longlist->next;
		shortlist = shortlist->next;
	}
	return  longlist;
}